package com.zsoft.util;

import java.math.BigDecimal;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 类型转换类
 * 
 * @author zuoshuaiok@gmail.com
 * 
 *         2013-4-22
 */
public class NumberFormatUtils {

	private static Logger logger = LoggerFactory
			.getLogger(NumberFormatUtils.class);

	public static int resolveString(String str, int def) {

		try {
			def = Integer.parseInt(str);
		} catch (NumberFormatException e) {
			logger.warn("类型转换出错--" + str + e);
		}

		return def;
	}

	public static BigDecimal roundNumber(double divisor, double dividend) {
		BigDecimal bd = new BigDecimal(0);
		if (divisor != 0.0 && dividend != 0.0) {
			bd = new BigDecimal(divisor / dividend).setScale(2,
					BigDecimal.ROUND_HALF_UP);
		}
		return bd;
	}

}
